package com.bt.config;

import com.bt.interceptoor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//扩展SpringMvc
@Configuration
public class MvcConfig implements WebMvcConfigurer {

	//扩展视图控制器 映射器
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		//浏览器发送/welcome请求 到达welcome页面
		registry.addViewController("/welcome").setViewName("index");
		registry.addViewController("/login").setViewName("login");
		registry.addViewController("/main").setViewName("main");
		registry.addViewController("/toaddUser").setViewName("add");
		registry.addViewController("/toRegister").setViewName("register"); //添加请求
		registry.addViewController("/toRegister").setViewName("register"); //添加请求
//添加过滤规则-忽略注册请求
	}

	//拦截器-登录拦截器
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/*")
				.excludePathPatterns("/login","/index","/dologin","/toRegister","/register");

	}
	}
